package com.djzhu.algorithm.sort;

/**
 * Descriptions...
 *
 * @author DJ.Zhu
 */
public class ShellSort extends AbstractSort {

    @Override
    void sort(Integer[] array) {
        //增量每次都/2
        for (int step = array.length / 2; step > 0; step /= 2) {
            System.out.println("step:" + step);
            //从增量那组开始进行插入排序，直至完毕
            for (int i = step; i < array.length; i++) {
                print(array);
                int j = i;
                int temp = array[j];

                // j - step 就是代表与它同组隔壁的元素
                while (j - step >= 0 && array[j - step] > temp) {
                    array[j] = array[j - step];
                    j = j - step;
                }
                array[j] = temp;
            }
        }
    }
}
